<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="租房合同编号" prop="cfContractNo">
        <el-input
          v-model="queryParams.cfContractNo"
          placeholder="请输入租房合同编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="小区名" prop="premiseName">
        <el-input
          v-model="queryParams.premiseName"
          placeholder="请输入小区名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="租客姓名" prop="tenantName">
        <el-input
          v-model="queryParams.tenantName"
          placeholder="请输入租客姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="合同录入日期" prop="inputDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.startDates"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择合同录入起始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="-" prop="signingDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.endDates"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择合同录入截止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同编号" align="center" prop="cfContractNo" />
      <el-table-column label="小区名(使用楼盘名称)" align="center" prop="premiseName" />
      <el-table-column label="租客姓名" align="center" prop="tenantName" />
      <el-table-column label="租约期限开始日" align="center" prop="startDate" width="180">

        <template slot-scope="scope">
          <el-time-select
            v-model="scope.row.startDate">
          </el-time-select>
        </template>
      </el-table-column>
      <el-table-column label="租约期限结束日" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <el-time-select
            v-model="scope.row.endDate">
          </el-time-select>
        </template>
      </el-table-column>
      <el-table-column label="合同录入日期" align="center" prop="inputDate" width="180">
        <template slot-scope="scope">
          <el-time-select
            v-model="scope.row.inputDate">
          </el-time-select>
        </template>
      </el-table-column>
      <el-table-column label="合同审核日期" align="center" prop="auditDate" width="180">
        <template slot-scope="scope">
          <el-time-select
            v-model="scope.row.auditDate">
          </el-time-select>
        </template>
      </el-table-column>
      <el-table-column label="合同录入人" align="center" prop="username" />
      <el-table-column label="合同生成" align="center" prop="auditDate" width="180">
        <el-button type="primary" size="mini" @click="genPdf">生成</el-button>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { genPdf,listContract, getContract, delContract, addContract, updateContract } from "@/api/termination/contraction";

export default {
  name: "Contraction",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      contractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        startDates:null,
        endDates:null,
        pageNum: 1,
        pageSize: 10,
        cfContractNo: null,
        premiseName: null,
        tenantName: null,
        username: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    genPdf(){
      genPdf().then(resp=>{
        alert("合同生成成功")
      })
    },
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        console.log(response)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        startDate:null,
        endDate:null,
        id: null,
        cfContractNo: null,
        outContractNo: null,
        lastContractId: null,
        lastContractNo: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        sfContractId: null,
        sfContractNo: null,
        houseId: null,
        houseName: null,
        premiseName: null,
        peopleNum: null,
        tenantId: null,
        tenantName: null,
        tenantPhone: null,
        tenantEmergencyPhone: null,
        tenantCardNo: null,
        tenantContactAddress: null,
        startDate: null,
        endDate: null,
        signingCycle: null,
        monthRent: null,
        deposit: null,
        depositType: null,
        paymentType: null,
        advanceDays: null,
        fixedDay: null,
        tenantExpenses: null,
        signType: null,
        supplementaryTerms: null,
        haveSpecialPeople: null,
        rentInstallmentFlg: null,
        zyblFlg: null,
        contractState: null,
        xuyueState: null,
        freezeStatus: 0,
        inputDate: null,
        signingDate: null,
        auditDate: null,
        inputUserId: null,
        cfUserId: null,
        cfUserName: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContract(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContract(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delContract(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contract/export', {
        ...this.queryParams
      }, `system_contract.xlsx`)
    }
  }
};
</script>
